﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace DRSM
{
    public partial class PhysicalAid : Form
    {
        bool itemName = false;        
        bool quantity = false;
        bool rdncheck = false;

        public PhysicalAid()
        {
            InitializeComponent();
            this.lblTime.Text = DateTime.Now.ToString();
            this.timer1.Start();
            this.timer2.Start();
           
        }

        private void btnFinanicalAid_Click(object sender, EventArgs e)
        {
            AllFormClass.pa.Hide();
            //AllFormClass.fa.Show();

        }


        private void tbxAffectedcitiesMainMenu_Click(object sender, EventArgs e)
        {

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }

        private void lblDeletePhysicalAidTitle_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void PhysicalAid_Load(object sender, EventArgs e)
        {
            pnlAddPhysicalAidManagenmentSub.Show();
            pnlAddPysicalAidManagement.Show();
            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Hide();
            //pnlUpdateAffectedCities.Hide();
            pnlUpdatePhysicalAidManagement.Hide();           
            pnlUpdatePhysicalAidSub.Hide();
            pnlViewAllPhysicalAidManagement.Hide(); 
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox3_Click_1(object sender, EventArgs e)
        {

        }

        private void pbxPhysicalAidSubMenu_Click(object sender, EventArgs e)
        {

        }

        private void pnlAddPhysicalAidManagenmentSub_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pnlDeleteSupportPersonnelFromAffectedCity1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pnlAddPysicalAidManagement_Paint(object sender, PaintEventArgs e)
        {

        }

        private void cbxAssignName_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void pnlDeleteAssignAffectedCities_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnBack_Click(object sender, EventArgs e)
        {

        }

        private void lblAddPhysicalAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlAddPysicalAidManagement.Show();
            pnlAddPhysicalAidManagenmentSub.Show();

            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Hide();
            //pnlUpdateAffectedCities.Hide();
            pnlUpdatePhysicalAidManagement.Hide();
            pnlUpdatePhysicalAidSub.Hide();           
            pnlViewAllPhysicalAidManagement.Hide();
            
        }

        private void lblUpdatePhysicalAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlAddPhysicalAidManagenmentSub.Hide();
            pnlAddPysicalAidManagement.Hide();
            pnlUpdatePhysicalAidManagement.Show();
            pnlUpdatePhysicalAidSub.Hide();
            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Hide();
            //pnlUpdateAffectedCities.Hide();            
            pnlViewAllPhysicalAidManagement.Hide();   
        }

        private void lblDeletePhysicalAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlAddPhysicalAidManagenmentSub.Hide();
            pnlAddPysicalAidManagement.Hide();
            pnlUpdatePhysicalAidManagement.Hide();
            pnlUpdatePhysicalAidSub.Hide();
            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Show();
            //pnlUpdateAffectedCities.Hide();
            pnlViewAllPhysicalAidManagement.Hide();

            PhysicalAidControl.DeletePhysicalAid(a1, dgvDeletePhysicalAid);
            /*dgvDeletePhysicalAid.DataSource = null;
            dgvDeletePhysicalAid.Refresh();
            if (AllFormClass.PhysicalAids.Count > 0)
            {
                dgvDeletePhysicalAid.DataSource = AllFormClass.PhysicalAids;
                dgvDeletePhysicalAid.Refresh();
            }*/
                
            
        }
               

        private void lblViewAllPhysicalAid_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlAddPhysicalAidManagenmentSub.Hide();
            pnlAddPysicalAidManagement.Hide();
            pnlUpdatePhysicalAidManagement.Hide();
            pnlUpdatePhysicalAidSub.Hide();
            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Hide();
            //pnlUpdateAffectedCities.Hide();
            pnlViewAllPhysicalAidManagement.Show();

            PhysicalAidControl.ViewPhysicalAid(dgvViewAllPhysicalAidManagement);


            /*dgvViewAllPhysicalAidManagement.DataSource = null;
            dgvViewAllPhysicalAidManagement.Refresh();
            if (AllFormClass.PhysicalAids.Count > 0)
            {
                dgvViewAllPhysicalAidManagement.DataSource = AllFormClass.PhysicalAids;
                dgvViewAllPhysicalAidManagement.Refresh();
            }*/

            
            //int rowCount = dgvViewAllPhysicalAidManagement.RowCount;
            //for (int j = 0; j < rowCount; j++)
            //{
            //    //clear the datagridview
            //    dgvViewAllPhysicalAidManagement.Rows.Clear();
            //}

            //for (int i = 0; i < AllFormClass.PhysicalAids.Count; i++)
            //{
            //    PhysicalAids p = (PhysicalAids)AllFormClass.PhysicalAids[i];
            //    dgvViewAllPhysicalAidManagement.Rows.Add();
            //    dgvViewAllPhysicalAidManagement.Rows[i].Cells[0].Value = p.ItemName;
            //    dgvViewAllPhysicalAidManagement.Rows[i].Cells[1].Value = p.Quantity;
            //    dgvViewAllPhysicalAidManagement.Rows[i].Cells[2].Value = p.Description;
            //    dgvViewAllPhysicalAidManagement.Rows[i].Cells[4].Value = p.City;
            //    dgvViewAllPhysicalAidManagement.Rows[i].Cells[3].Value = p.TypeOfItems;
            //}

        }

        private void lblAssignAffectedCities_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlAddPhysicalAidManagenmentSub.Hide();
            pnlAddPysicalAidManagement.Hide();
            pnlUpdatePhysicalAidManagement.Hide();
            pnlUpdatePhysicalAidSub.Hide();
            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Hide();
            //pnlUpdateAffectedCities.Hide();
            pnlViewAllPhysicalAidManagement.Hide();
            //pnlAssign.Show();
           
            //cbxAssignName.Items.Clear();
            //for (int i = 0; i < AllFormClass.PhysicalAids.Count; i++)
            //{
            //    PhysicalAids p2 = (PhysicalAids)AllFormClass.PhysicalAids[i];
            //    cbxAssignName.Items.Add(p2);
            //}
        }

        private void lblUpdateAffectedCities_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlAddPhysicalAidManagenmentSub.Hide();
            pnlAddPysicalAidManagement.Hide();
            pnlUpdatePhysicalAidManagement.Hide();
            pnlUpdatePhysicalAidSub.Hide();
            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Hide();
            //pnlUpdateAffectedCities.Show();
            pnlViewAllPhysicalAidManagement.Hide();   
        }

        //private void lblDeleteAssignAffectedCities_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        //{
        //    pnlAddPhysicalAidManagenmentSub.Hide();
        //    pnlAddPysicalAidManagement.Hide();
        //    pnlUpdatePhysicalAidManagement.Hide();
        //    pnlUpdatePhysicalAidSub.Hide();
        //    //pnlAssignAffectedCities.Hide();
        //    //pnlDeleteAssignAffectedCities.Show();
        //    pnlDeletePhysicalAidManagement.Hide();
        //    //pnlUpdateAffectedCities.Hide();
        //    pnlViewAllPhysicalAidManagement.Hide();   
        //}

        private void btnPhysicalAidManagement_Click(object sender, EventArgs e)
        {
            pnlAddPhysicalAidManagenmentSub.Show();
            pnlAddPysicalAidManagement.Show();
            pnlUpdatePhysicalAidManagement.Hide();
            pnlUpdatePhysicalAidSub.Hide();
            //pnlAssignAffectedCities.Hide();
            //pnlDeleteAssignAffectedCities.Hide();
            pnlDeletePhysicalAidManagement.Hide();
            //pnlUpdateAffectedCities.Hide();
            pnlViewAllPhysicalAidManagement.Hide();   
        }

        private void pbxHeader_Click(object sender, EventArgs e)
        {

        }

        private void btnAffectedCitiesManagement_Click(object sender, EventArgs e)
        {
            AllFormClass.ac.Show();
            this.Hide();
        }

        private void btnSupportPersonnelManagement_Click(object sender, EventArgs e)
        {
            AllFormClass.sp.Show();
            this.Hide();
        }

       // int count = 0;
        private void btnAdd_Click(object sender, EventArgs e)
        {
            PhysicalAidControl.AddPhysicalAid(tbxItemNameAddPhyscialAid, tbxQuantity, rtbDescriptionAddPhyscialAid, rdnBtnFood, rdnBtnClothes, rdnBtnBlanket);
            /*count++;         
           
            string itemName = tbxItemNameAddPhyscialAid.Text.Trim();
            string itemQuantity = tbxQuantity.Text.Trim();
            string itemDesc = rtbDescriptionAddPhyscialAid.Text.Trim();


            string type = "";
            if (rdnBtnFood.Checked.Equals(true)) 
            {
                type = "Food";
            }
            if (rdnBtnClothes.Checked.Equals(true))
            {
                type = "Clothes";
            }
            if (rdnBtnBlanket.Checked.Equals(true))
            {
                type = "Blanket";
            }

            //generate random number
            int num = 10000;
            num = num + count;

            //Initialize boolean values to check if each field is empty
            bool empty = false;
            if (empty == false)
            {
                PhysicalAids p = new PhysicalAids(type, itemName, itemQuantity, itemDesc, num);
                AllFormClass.PhysicalAids.Add(p);
            }

           
            MessageBox.Show("Item Added Successfully!");

            //clear all textbox and field
            //tbxItemIdentificationNumberAddPhyscialAid.Clear();                       
            //tbxEnterCityAddPhyscialAid.Clear();
            tbxItemNameAddPhyscialAid.Clear(); 
            tbxQuantity.Clear();
            rdnBtnFood.Checked = false;
            rdnBtnClothes.Checked = false;
            rdnBtnBlanket.Checked = false;
            rtbDescriptionAddPhyscialAid.Clear();*/

        }

        private void btnViewPhysicalAidSearch_Click(object sender, EventArgs e)
        {
            
        }

        private void comboBoxTypesOfItemsAddPhyscialAid_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void pnlViewAllPhysicalAidManagement_Paint(object sender, PaintEventArgs e)
        {

        }

        private void dgvViewAllPhysicalAidManagement_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void rdnBtnClothes_CheckedChanged(object sender, EventArgs e)
        {
            rdncheck = true;
            if (itemName && quantity && rdncheck)
            {
                this.btnAdd.Enabled = true;

            }
            else
            {
                this.btnAdd.Enabled = false;
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {

        }

        private void btnSelect_Click(object sender, EventArgs e)
        {

        }

        private void buttonSearch_Click(object sender, EventArgs e)
        {

        }

        PhysicalAids p;
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            ArrayList integer = new ArrayList();
            foreach (DataGridViewRow row in dgvDeletePhysicalAid.SelectedRows)
            {
                integer.Add(row.Cells[0].Value);
            }
            PhysicalAidControl.DeletePhysicalAid(integer, dgvDeletePhysicalAid);
 
            //PhysicalAidControl.deletePhysicalAid(dgvDeletePhysicalAid, p);
            /*foreach (DataGridViewRow row in dgvDeletePhysicalAid.SelectedRows)
            {

                int intIndex;
                intIndex = dgvDeletePhysicalAid.CurrentCell.RowIndex;

                p1 = (PhysicalAids)AllFormClass.PhysicalAids[intIndex];
                AllFormClass.PhysicalAids.Remove(p1);

                dgvDeletePhysicalAid.DataSource = null;
                dgvDeletePhysicalAid.Refresh();

                dgvDeletePhysicalAid.DataSource = AllFormClass.PhysicalAids;
                dgvDeletePhysicalAid.Refresh();

            }*/

            
        }

        private void tbxItemNameAddPhyscialAid_TextChanged(object sender, EventArgs e)
        {
            itemName = tbxItemNameAddPhyscialAid.Text != "";
            if (itemName && quantity && rdncheck)
            {
                this.btnAdd.Enabled = true;

            }
            else
            {
                this.btnAdd.Enabled = false;
            }

        }

        //private void tbxEnterCityAddPhyscialAid_TextChanged(object sender, EventArgs e)
        //{
        //    city = tbxEnterCityAddPhyscialAid.Text != "";
        //    if (itemName && city && quantity && rdncheck)
        //    {
        //        this.btnAdd.Enabled = true;

        //    }
        //    else
        //    {
        //        this.btnAdd.Enabled = false;
        //    }

        //}

        private void tbxQuantity_TextChanged(object sender, EventArgs e)
        {
            quantity = tbxQuantity.Text != "";
            if (itemName && quantity && rdncheck)
            {
                this.btnAdd.Enabled = true;

            }
            else
            {
                this.btnAdd.Enabled = false;
            }            
        }

        private void rdnBtnFood_CheckedChanged(object sender, EventArgs e)
        {
            rdncheck = true;
            if (itemName && quantity && rdncheck)
            {
                this.btnAdd.Enabled = true;

            }
            else
            {
                this.btnAdd.Enabled = false;
            }
        }

        private void rdnBtnBlanket_CheckedChanged(object sender, EventArgs e)
        {
            rdncheck = true;
            if (itemName && quantity && rdncheck)
            {
                this.btnAdd.Enabled = true;

            }
            else
            {
                this.btnAdd.Enabled = false;
            }
        }
        private bool nonLetterEntered = false;

        private void tbxItemNameAddPhyscialAid_KeyDown(object sender, KeyEventArgs e)
        {
            // Initialize the flag to false.
            nonLetterEntered = false;

            // Determine whether the keystroke is a number from the top of the keyboard.
            if (e.KeyCode < Keys.A || e.KeyCode > Keys.Z)
            {
                //// Determine whether the keystroke is a number from the keypad.
                //if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                //{
                // Determine whether the keystroke is a backspace.
                if (e.KeyCode != Keys.Back)
                {
                    // A non-numerical keystroke was pressed.
                    // Set the flag to true and evaluate in KeyPress event.
                    nonLetterEntered = true;
                }
                //}
            }
            //If shift key was pressed, it's not a number.
            if (Control.ModifierKeys == Keys.Shift)
            {
                nonLetterEntered = true;
            }
        }

        private void tbxItemNameAddPhyscialAid_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (nonLetterEntered == true)
            {
                e.Handled = true;
            }
        }

        private void lblQuantityUpdatePhysicalAidManagement_Click(object sender, EventArgs e)
        {

        }

        private void btnUpdateAffectedCitySearch_Click(object sender, EventArgs e)
        {
            //string input = tbxUpdatePhysicalAidManagementSearch.Text.Trim();
            //if (input.Length == 0)
            //{
            //    tbxUpdatePhysicalAidManagementSearch.Focus();
            //}
            //else
            //{
            //    UpdatePhysicaAid.Items.Clear;
            //}
            //for (int i = 0; i < AllFormClass.PhysicalAids.Count; i++) 
            //{
            //    PhysicalAids p = (PhysicalAids)AllFormClass.PhysicalAids[i];
            //    string searchItem = p.ItemName;
            //    if (searchItem.Contains(tbxUpdatePhysicalSearch.Text)) 
            //    {
            //        UpdatePhysicaAid.DisplayMember = "ItemName";
            //        UpdatePhysicaAid.Items.Add(AllFormClass.PhysicalAids[i]);
            //    }
            //}            
        }

        //private void tbxUpdatePhysicalAidManagementSearch_TextChanged(object sender, EventArgs e)
        //{
        //    this.UpdatePhysicaAid.Items.Clear();

        //    if (tbxUpdatePhysicalSearch.Text != String.Empty)
        //    {
        //        for (int i = 0; i < AllFormClass.PhysicalAids.Count; i++)
        //        {
        //            PhysicalAids p = (PhysicalAids)AllFormClass.PhysicalAids[i];
        //            string searchItem = p.ItemName.ToString();
        //            if (searchItem.Contains(tbxUpdatePhysicalSearch.Text))
        //            {
        //                UpdatePhysicaAid.DisplayMember = "ItemName";
        //                UpdatePhysicaAid.Items.Add(p.ItemName);
        //            }
        //        }
        //    }
        //}

        private void UpdatePhysicaAid_SelectedIndexChanged(object sender, EventArgs e)
        {

            try
            {
                string selectedItem = UpdatePhysicaAid.SelectedItem.ToString();
               // foreach (PhysicalAids PhysicalAids in AllFormClass.PhysicalAids)
                for (int i = 0; i < AllFormClass.PhysicalAids.Count; i++)
                {
                    //PhysicalAids p = (PhysicalAids)UpdatePhysicaAid.SelectedItem;

                     PhysicalAids p = ((PhysicalAids)AllFormClass.PhysicalAids[i]);

                    if (p.ItemName == selectedItem)
                    {
                        //textBox1.Text = Convert.ToString(PhysicalAids.ItemID);
                        tbxItemNameUpdatePhysicalAid.Text = p.ItemName;
                        tbxQuantityUpdatePhysicalAid.Text = p.Quantity;
                        rtbDescriptionUpdatePhysicalAid.Text = p.Description;
                        textBox1.Text = p.ItemID.ToString();
                        
                        if (p.Type.Equals("Food"))
                        {
                            radioButtonUpdateFood.Select();
                        }
                        else if (p.Type.Equals("Clothes"))
                        {
                            radioButtonUpdateClothes.Select();
                        }
                        else if (p.Type.Equals("Blanket"))
                        {
                            radioButtonUpdateBlacket.Select();
                        }
                        //if (radioButtonUpdateFood.Checked.Equals(true))
                        //{
                        //    PhysicalAids.Type = "FOOD";
                        //}
                        //if (radioButtonUpdateBlacket.Checked.Equals(true))
                        //{
                        //    PhysicalAids.Type = "BLANKET";
                        //}
                        //if (radioButtonUpdateClothes.Checked.Equals(true))
                        //{
                        //    PhysicalAids.Type = "CLOTHES";
                        //}
                       
                    }
                    pnlUpdatePhysicalAidSub.Show();
                }
                
            }
            catch (NullReferenceException)
            {
                return;
            }
            //catch (InvalidCastException ice)
            //{
            //    return; 
            //}
        }

        private void tbxQuantityUpdatePhysicalAid_TextChanged(object sender, EventArgs e)
        {

        }

        private void tbxUpdatePhysicalSearch_TextChanged_1(object sender, EventArgs e)
        {
            this.UpdatePhysicaAid.Items.Clear();

            if (tbxUpdatePhysicalSearch.Text != String.Empty)
            {
                for (int i = 0; i < AllFormClass.PhysicalAids.Count; i++)
                {
                    //PhysicalAids p = (PhysicalAids)AllFormClass.PhysicalAids[i];
                    //string searchItem = p.ItemName.ToString();

                    PhysicalAids p = ((PhysicalAids)AllFormClass.PhysicalAids[i]);

                    string searchItem = p.ItemName.ToString();

                    if (searchItem.Contains(tbxUpdatePhysicalSearch.Text))
                    {
                        UpdatePhysicaAid.DisplayMember = "ItemName";
                        UpdatePhysicaAid.Items.Add(p.ItemName);
                    }
                }
            }
        }

        private void lblPhysicalManagement_Click(object sender, EventArgs e)
        {

        }
               
        private void rtbDescriptionAddPhyscialAid_TextChanged(object sender, EventArgs e)
        {
           
        }

        //Boolean flag used to determine when a character other than a number is entered.
        
        private bool nonNumberEntered = false;
        private ArrayList a1;
        private void tbxQuantity_KeyDown(object sender, KeyEventArgs e)
        {
            //initialize the flag to false
            nonNumberEntered = false;

            //Determine whether the keystroke is a number from the top
            if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9) 
            {
                // Determine whether the keystroke is a number from the keypad.
                if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)                                                    
                {
                    // Determine whether the keystroke is a backspace.
                    if (e.KeyCode !=Keys.Back) 
                    {
                        // A non-numerical keystroke was pressed.
                        // Set the flag to true and evaluate in KeyPress event.
                        nonNumberEntered = true;
                    }
                }
            }
            //if shift key was press, it's not a number
            if (Control.ModifierKeys == Keys.Shift)
            {
                nonNumberEntered = true;
            }
        }

        private void tbxQuantity_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Check for the flag being set in the KeyDown event.
            if (nonNumberEntered == true)
            {
                // Stop the character from being entered into the control since it is non-numerical.
                e.Handled = true;
            }
        }

        private void pnlUpdatePhysicalAidSub_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnUpdateUpdatePhysicalAid_Click(object sender, EventArgs e)
        {
            PhysicalAidControl.UpdatePhysicalAid(tbxItemNameUpdatePhysicalAid, tbxQuantityUpdatePhysicalAid, rtbDescriptionUpdatePhysicalAid,
            radioButtonUpdateFood, radioButtonUpdateClothes, radioButtonUpdateBlacket, textBox1);
            /*foreach (PhysicalAids PhysicalAids in AllFormClass.PhysicalAids)
            {
                //check ur id
                if (Convert.ToString(PhysicalAids.ItemID) == textBox1.Text)
                {
                    PhysicalAids.ItemName = tbxItemNameUpdatePhysicalAid.Text;
                    PhysicalAids.Quantity = tbxQuantityUpdatePhysicalAid.Text;
                    PhysicalAids.Description = rtbDescriptionUpdatePhysicalAid.Text;

                    if (radioButtonUpdateFood.Checked.Equals(true))
                    {
                        PhysicalAids.Type = "Food";
                    }
                    if (radioButtonUpdateClothes.Checked.Equals(true))
                    {
                        PhysicalAids.Type = "Clothes";
                    }
                    if (radioButtonUpdateBlacket.Checked.Equals(true))
                    {
                        PhysicalAids.Type = "Blacket";
                    }
                }

               // break;
            }
            MessageBox.Show("Physical Aid Updated Successfully!");*/
        }

        private void tbxNameOfCity_TextChanged(object sender, EventArgs e)
        {
            //AffectedCity a1 = (AffectedCity)lbxAssignSearchResult.SelectedItem;
            //Search for the AffectedCity selected
            //for (int j = 0; j < AllFormClass.AffectedCity.Count; j++)
            //{

            //    AffectedCity ac = (AffectedCity)AllFormClass.AffectedCity[j];
            //    if ()
            //    {
            //        tbxNameOfCity.Text = ac.NameOfCity;
            //    }
            //}
        }

        private void btnAssignAssignAffectedCities_Click(object sender, EventArgs e)
        {
            
            //for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            //{
            //    AffectedCity ac = (AffectedCity)AllFormClass.AffectedCity[i];
            //    //PhysicalAids pa = (PhysicalAids)tbxNameOfCity.Contains;
            //}
        }

        private void cbxAssignSearch_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btnAssignSearch_Click(object sender, EventArgs e)
        {

            //string input = tbxAssignSearch.Text.Trim();
            //if (input.Length == 0)
            //{
            //    tbxAssignSearch.Focus();
            //}
            //else
            //{
            //    lbxAssignSearchResult.Items.Clear();
            //    if (cbxAssignSearch.SelectedItem.Equals("CityID"))
            //    {
            //        for (int j = 0; j < AllFormClass.AffectedCity.Count; j++)
            //        {
            //            AffectedCity ac = (AffectedCity)AllFormClass.AffectedCity[j];
            //            bool result = Convert.ToString(ac.CityID1).Contains(tbxAssignSearch.Text);
            //            if (result == true)
            //            {
            //                lbxAssignSearchResult.DisplayMember = "CityID";
            //                lbxAssignSearchResult.Items.Add(ac);
            //            }
            //        }
            //    }
            //    else if (cbxAssignSearch.SelectedItem.Equals("CityName"))
            //    {
            //        for (int j = 0; j < AllFormClass.AffectedCity.Count; j++)
            //        {
            //            AffectedCity ac = (AffectedCity)AllFormClass.AffectedCity[j];
            //            bool result = Convert.ToString(ac.NameOfCity).Contains(tbxAssignSearch.Text);
            //            if (result == true)
            //            {
            //                lbxAssignSearchResult.DisplayMember = "CityName";
            //                lbxAssignSearchResult.Items.Add(ac);
            //            }
            //        }
            //    }
            //}          
        }

        private void btnAssignSelect_Click(object sender, EventArgs e)
        {
            //AffectedCity a1 = (AffectedCity)lbxAssignSearchResult.SelectedItem;
            //try
            //{
            //    if (cbxAssignSearch.SelectedIndex == 1)
            //    {
            //        //Search for the AffectedCity selected
            //        for (int j = 0; j < AllFormClass.AffectedCity.Count; j++)
            //        {

            //            AffectedCity ac = (AffectedCity)AllFormClass.AffectedCity[j];
            //            if (a1.CityID1 == ac.CityID1)
            //            {
            //                tbxNameOfCity.Text = ac.NameOfCity;
            //            }
            //        }
            //    }
            //    else if (cbxAssignSearch.SelectedIndex == 2)
            //    {
            //        //Search for the AffectedCity selected
            //        for (int j = 0; j < AllFormClass.AffectedCity.Count; j++)
            //        {
            //            AffectedCity ac = (AffectedCity)AllFormClass.AffectedCity[j];
            //            if (a1.NameOfCity == ac.NameOfCity)
            //            {
            //                tbxNameOfCity.Text = ac.NameOfCity;
            //            }
            //        }
            //    }

            //    //Add in PhysicalAid Availiable
            //    for (int j = 0; j < AllFormClass.PhysicalAids.Count; j++)
            //    {
            //        PhysicalAids p = (PhysicalAids)AllFormClass.PhysicalAids[j];
            //        cbxAssignName.DisplayMember = "ItemName";
            //        cbxAssignName.Items.Add(p);
            //    }

            //    //Link to next panel
            //    pnlAssignAffectedCities.Show();
            //    pnlAssign.Hide();
            //}
            //catch (NullReferenceException)
            //{
            //    return;
            //}           
        }

        private void lbxAssignSearchResult_SelectedIndexChanged(object sender, EventArgs e)
        {
            //string selectTitle = lbxAssignSearchResult.SelectedItem.ToString();
            //foreach (PhysicalAids PhysicalAids in AllFormClass.PhysicalAids)
            //{
            //    if (PhysicalAids.ItemName == selectTitle)
            //    {
            //        dgvAssignAffectedCities.DataSource = null;
            //        dgvAssignAffectedCities.Refresh();
            //    }
            //}
            //string affectedCityRequired = lbxAssignSearchResult.Text;
           
            //for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            //{
            //    PhysicalAids p = (PhysicalAids)AllFormClass.PhysicalAids[i];                
                

            //}
        }

        private void lblLogout_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult dr = MessageBox.Show("Are you sure you want to logout?",
                  "Warning",
                  MessageBoxButtons.YesNo,
                  MessageBoxIcon.Exclamation);

            if (dr == DialogResult.Yes)
            {
                AllFormClass.lp.Show();
                this.Hide();
            }
            else if (dr == DialogResult.No)
            {

            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.lblTime.Text = DateTime.Now.ToString();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            foreach (user u in AllFormClass.User)
            {
                if (u.Name == u.Name)
                {
                    this.lblWelcome.Text = "Welcome, " + u.Name;
                }
            }
        }

        private void lblAddPhysicalAidManagement_Click(object sender, EventArgs e)
        {

        }

        private void pnlUpdateAffectedCities_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tbxAssignSearch_TextChanged(object sender, EventArgs e)
        {
            //this.lbxAssignSearchResult.Items.Clear();
            //if (tbxAssignSearch.Text != string.Empty)
            //{
            //    for (int i = 0; i < AllFormClass.PhysicalAids.Count; i++)
            //    {
            //        PhysicalAids p = (PhysicalAids)AllFormClass.PhysicalAids[i];
            //        string searchItem = p.ItemName.ToString();
            //        if (searchItem.Contains(tbxAssignSearch.Text))
            //        {
            //            lbxAssignSearchResult.DisplayMember = "ItemName";
            //            lbxAssignSearchResult.Items.Add(p.ItemName);
            //        }
            //    }               
            //}
        }

        private void btnAssign_Click(object sender, EventArgs e)
        {
            
        }


    }
} 
